package com.stek.main;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.stek.R;
import com.stek.utils.Utils;

public class MainBaseAdapter extends BaseAdapter {
	private ArrayList<MainInfo> list;
	private Context context;

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();

	}

	public MainBaseAdapter(ArrayList<MainInfo> list, Context context) {
		super();
		this.list = list;
		this.context = context;
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Holder holder;
		if (null == convertView) {
			convertView = LayoutInflater.from(context).inflate(
					R.layout.row_common, null);
			holder = new Holder();
			holder.tv = (TextView) convertView.findViewById(R.id.tv_name);
			convertView.setTag(holder);
		} else {
			holder = (Holder) convertView.getTag();
		}

		holder.tv.setText(list.get(position).name);
		holder.tv.setCompoundDrawablesWithIntrinsicBounds(
				list.get(position).resId, 0, 0, 0);
		Utils.animateListView((ListView)parent, convertView, position);
		return convertView;
	}

	static class Holder {
		TextView tv;
	}

}
